<div class="box box-skin main-content">	
	<div class="box-body no-padding">
	    <div id="toolbar">
			<div class="form-inline" role="form">
		    	<div class="form-group btn-group">
                    <button type="button" class="btn btn-default btn-flat" onclick="CRUDUserFunc(1);" title="添加"><i class="fa fa-plus"></i></button>
                    <button type="button" class="btn btn-default btn-flat" onclick="CRUDUserFunc(5);" title="批量删除"><i class="fa fa-trash"></i></button>
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" name="likeMap[username]" placeholder="登录名" />
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" name="likeMap[real_name]" placeholder="姓名" />
                </div>
		    	<div class="form-group btn-group">
                	<button type="button" class="btn btn-default btn-flat" onclick="searchFunc();" title="搜索"><i class="fa fa-search"></i></button>
                	<button type="button" class="btn btn-default btn-flat" onclick="reloadFunc();" title="重新加载"><i class="fa fa-refresh"></i></button>
				</div>
            </div>
	    </div>
		
		<table id="table"></table>
	</div>
</div>

<script type="text/javascript" src="__TMPL__Public/pages/admin/user.js"></script>
<script type="text/javascript">
$(function() {
	$('#table').bootstrapTable({
		classes: 'table table-no-bordered table-hover',
		striped: true,
		toolbar: '#toolbar',
		showColumns: true,
	    showPaginationSwitch: true,
	    pagination: true,
		sidePagination: 'server',
		pageSize: 10,
		pageList: '[10, 15, 50, 100, All]',
		queryParams: queryParams,
		queryParamsType: 'limit',
		sortName: 'id',
		sortOrder: 'desc',
		url: "{:U('Admin/User/dataList')}",
	    idField: 'id',
	    columns: [{
            field: 'state',
            checkbox: true,
            visible: false,
//			width: '20%',
            align: 'left',
            valign: 'middle',
        }, {
	        title: 'ID',
	        field: 'id',
	        sortable: true,
            visible: false,
//			width: '20%',
            align: 'left',
            valign: 'middle',
	    }, {/*
	        title: '头像',
	        field: 'avatar',
//			width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
            	return value != '' ? '<img alt="no pic" src="' + value + '" class="" style="height: 45px; display: block;">' : '<img alt="no pic" src="./static/img/avatar.png" class="" style="height: 45px; display: block;">';
            },
	    }, {*/
	        title: '登录名',
	        field: 'username',
	        sortable: true,
//			width: '20%',
            align: 'left',
            valign: 'middle',
	    }, {
	        title: '姓名',
	        field: 'real_name',
	        sortable: true,
//			width: '20%',
            align: 'left',
            valign: 'middle',
	    }, {
	        title: '邮箱',
	        field: 'email',
//			width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
            	return value != '' ? value : '<span class="text-gray">无</span>';
    		},
	    }, {
	        title: '角色',
	        field: 'roleNameList',
            align: 'left',
            valign: 'middle',
//			width: '20%',
			formatter: function(value, row, index) {
				var str = '';
				if (!row.roleNames) {
					str = '<span class="text-gray">无</span>';
				} else {
					for (var i in row.roleNames) {
						str += row.roleNames[i] + ' ';
					}
				}
				return str;	
			},
		}, {
			title:'添加时间',
			field:'add_time',
	        sortable: true,
//			width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
           		return kk.timeFormat('yyyy-MM-dd HH:mm:ss', value);
    		},
	    }, {
	        title: '状态',
	        field: 'status',
//			width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
            	var str = '';
            	if (value == 0) {
            		str = '<span class="label label-warning">禁用</span>';
            	} else if (value == 1) {
            		str = '<span class="label label-success">启用</span>';
            	} else if (value == 2) {
            		str = '<span class="label label-default">未通过</span>';
            	} else if (value == -1) {
            		str = '<span class="label label-default">已删除</span>';
            	} else if (value == -2) {
            		str = '<span class="label label-default">已禁用</span>';
            	}
    			return str;
    		},
	    }, {
            title: '操作',
            field: 'operate',
//			width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
				var str = '';
				str += '<div class="btn-group">';
				str += '<button type="button" class="btn btn-default btn-flat btn-xs" onclick="CRUDUserFunc(2, ' + row.id + ');">查看</button>';
				str += '<button type="button" class="btn btn-default btn-flat btn-xs" onclick="CRUDUserFunc(3, ' + row.id + ', ' + index + ');">编辑</button>';
				str += '<button type="button" class="btn btn-default btn-flat btn-xs" onclick="forbiddenUserFunc('+ row.id + ', ' + index + ');">禁用</button>';
				str += '<button type="button" class="btn btn-default btn-flat btn-xs" onclick="CRUDUserFunc(4, ' + row.id + ');">删除</button>';
				str += '<button type="button" class="btn btn-default btn-flat btn-xs" onclick="addRoles('+ row.id + ', ' + index + ');">授权</button>';
				str += '</div>';
				return str;
			},
        }],
	});
});

/* search */
function queryParams(params) {
    $('#toolbar').find('input[name], select[name]').each(function () {
        params[$(this).attr('name')] = $(this).val();
    });
    return params;
}

function searchFunc() {
	$('#table').bootstrapTable('selectPage', 1);			// IMPORTANT!!!  有刷新功能!!!
}

/* reload */
function reloadFunc() {
	$('#toolbar').resetForm();
	$('#table').bootstrapTable('selectPage', 1);
}
</script>
